<?php

namespace app\admin\model;

use think\Model;

class Order extends Model
{
    // 表名
    protected $name = 'order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    
    // 追加属性
    protected $append = [
        'type_text',
        'status_text',
        'pay_manner_text',
        'time_text'
    ];
    

    
    public function getTypeList()
    {
        $typeArr = ['1'  =>  '云币支出', '2'  =>  '云币收入', '3'  =>  '其他',];
        //return ['1' => __('Type 1'),'2' => __('Type 2'),'3' => __('Type 3')];
        return $typeArr;
    }

    public function getStatusList()
    {
        $statusArr = ['0'  =>  '无效',
            '1'  =>  '未付款',
            '2'  =>  '已付款',
            '3'  =>  '已完成'];
        return $statusArr;
    }     

    public function getPayMannerList()
    {
        $payArr = ['0'  =>  '余额',
            '1'  =>  '支付宝',
            '2'  =>  '微信',
            '3'  =>  '银行卡'];
        return $payArr;
    }     


    public function getTypeTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['type'];
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['status'];
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPayMannerTextAttr($value, $data)
    {        
        $value = $value ? $value : $data['pay_manner'];
        $list = $this->getPayMannerList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : $data['time'];
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setTimeAttr($value)
    {
        return $value && !is_numeric($value) ? strtotime($value) : $value;
    }


}
